package cn.edu.cdtu.healthclient.connect;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils;

import cn.edu.cdtu.healthclient.domain.RegisterJson;
import cn.edu.cdtu.healthclient.utils.ConnectUtil;
import cn.edu.cdtu.healthclient.utils.ConnectUtil.RegisterPargrams;

import com.google.gson.Gson;

public class ConnectForRegister 
{
	public static RegisterJson connect(
			String accountRegister,String passwordRegister,
			String userNameRegister,HttpClient httpClient)
					throws ClientProtocolException, IOException
	{
		RegisterJson registerJson=null;
		String registerJsonString=null;
		HttpGet httpGet=new HttpGet(
									ConnectUtil.HealthServerContect.SERVER_URL
									+ ConnectUtil.HealthServerContect.REGISTER_SERVLET
									+ "?" 
									+ RegisterPargrams.Pargram.REGISTER_ACCOUNT
									+ "=" + accountRegister + "&"
									+ RegisterPargrams.Pargram.REGISTER_PASSWORD
									+ "=" + passwordRegister + "&"
									+ RegisterPargrams.Pargram.REGISTER_NAME
									+ "=" + userNameRegister
									);
		HttpResponse httpResponse=httpClient.execute(httpGet);
		if(httpResponse.getStatusLine().getStatusCode()==HttpStatus.SC_OK)
		{
			registerJsonString=EntityUtils.toString(httpResponse.getEntity(),"UTF-8");
			Gson gson=new Gson();
			registerJson=gson.fromJson(registerJsonString,RegisterJson.class);
		}
		return registerJson;
	}
}
